package com.heima.wemedia.controller.v1;

import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.dtos.WmAuthDto;
import com.heima.model.wemedia.dtos.WmNewsDto;
import com.heima.model.wemedia.dtos.WmNewsPageDto;
import com.heima.wemedia.service.WmNewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/v1/news")
public class WnNewsController {
    @Autowired
    private WmNewsService wmNewsService;

    /**
     * 文章列表查询
     *
     * @param dto
     * @return
     */
    @PostMapping("/list")
    public ResponseResult getList(@RequestBody WmNewsPageDto dto) {
        return wmNewsService.getList(dto);
    }

    /**
     * 发布文章
     * @param dto
     * @return
     */
    @PostMapping("submit")
    public ResponseResult submit(@RequestBody WmNewsDto dto) {
        return wmNewsService.submit(dto);
    }

    /**
     * 回显文章
     *
     * @param id
     * @return
     */
    @GetMapping("/one/{id}")
    public ResponseResult selectOne(@PathVariable Integer id) {
        return ResponseResult.okResult(wmNewsService.getById(id));
    }


    /**
     * 删除文章
     *
     * @param id
     * @return
     */
    @GetMapping("del_news/{id}")
    public ResponseResult deleteNews(@PathVariable Integer id) {
        return ResponseResult.okResult(wmNewsService.deleteById(id));
    }

    /**
     * 上下架文章
     *
     * @return
     */
    @PostMapping("down_or_up")
    public ResponseResult loadOrUnload(@RequestBody WmNewsDto dto) {
        return wmNewsService.loadOrUnload(dto);
    }

    /**
     * 管理端文章列表查询
     *
     * @param dto
     * @return
     */
    @PostMapping("/list_vo")
    public ResponseResult list_vo(@RequestBody WmNewsPageDto dto) {
        return wmNewsService.list_vo(dto);
    }

    /**
     * 管理端查看文章详情
     *
     * @param id
     * @return
     */
    @GetMapping("one_vo/{id}")
    public ResponseResult one_vo(@PathVariable Integer id) {
        return wmNewsService.one_vo(id);
    }

    /**
     * 人工审核文章通过
     * @param dto
     * @return
     */
    @PostMapping("/auth_pass")
    public ResponseResult auth_fail(@RequestBody WmAuthDto dto){
        return wmNewsService.authFailOrPass(dto);
    }

    /**
     * 人工审核文章驳回
     * @param dto
     * @return
     */
    @PostMapping("/auth_fail")
    public ResponseResult auth_pass(@RequestBody WmAuthDto dto){
        return wmNewsService.authFailOrPass(dto);
    }
}
